﻿// JavaScript Document


$(function () {
    //{{{全选
    $("input.button[name='selectall']").click(function () {
        if ($(this).attr("value") == "全选") {
            $("#datagrid input[type='checkbox']").each(function (index, item) {
                $(item).attr("checked", true)
            })
            $(this).attr("value", "取消全选")
        } else {
            $("#datagrid input[type='checkbox']").each(function (index, item) {
                $(item).attr("checked", false)
            })
            $(this).attr("value", "全选")
        }
    })
    //}}}

    //{{{删除
    $("input.button[name='delete']").click(function () {
        var ids = ""
        var id = 0;
        $("#datagrid input[type='checkbox']:checked").each(function (index, item) {
            ids = ids + $(item).val() + ","
            id = id + 1
        })
        if (ids != "") {
            alert("您选择了删除" + id + "个信息")
            return
        }
        else if (ids == "") {
            alert("请选择要删除的信息")
        }
        //console.log(ids)
    })
    //}}}

    //{{{编辑
    $("img.edit,input[name=add]").click(function () {
        $(".maincontent").mask()
        var $this = $(this)
        var msg = $this.parent().prev().html()
        if ($this.attr("name") == "add") {
            msg = ""
        }
        $("#cetd").show()
        $('#cetd').dialog({
            title: "Create/Edit"
            , iconCls: "icon-template"
            //, border: true
            , width: 457
            , height: 260
            , buttons: [{
                text: '保存'

                , handler: function () {
                    alert('你点了保存键');
                    $('#cetd').dialog('close');
                }
            }
            , {
                text: '取消'
                , handler: function () {
                    $('#cetd').dialog('close');
                }
            }]
            , onClose: function () {
                $(".maincontent").unmask()
            }
        }).find("textarea").val(msg);
    })
    //}}}

    //{{{删除单个
    $("img.delete").click(function () {
        $(".maincontent").mask()
        var $this = $(this)
        var msg = $this.parent().next().html()
        $.messager.defaults = { ok: "确定", cancel: "取消" }

        var _d = "<div class=\"messager-icon messager-question\"></div>" + "<div>" + "您确认要删除" + msg + "吗？" + "</div>" + "<div style=\"clear:both;\"/>";
        var _e = {};
        _e[$.messager.defaults.ok] = function () {
            _f.window("close");
            alert('你点了确认键');
        };
        _e[$.messager.defaults.cancel] = function () {
            _f.window("close");
        };

        var _f = $("<div class=\"messager-body\"></div>").appendTo("body");
        _f.append(_d);
        if (_e) {
            var tb = $("<div class=\"messager-button\"></div>").appendTo(_f);
            for (var _10 in _e) {
                $("<a></a>").attr("href", "javascript:void(0)").text(_10).css("margin-left", 10).bind("click", eval(_e[_10])).appendTo
(tb).linkbutton();
            }
        }

        _f.window({
            title: "删除确认",
            width: 300,
            height: "auto",
            modal: false,
            collapsible: false,
            minimizable: false,
            maximizable: false,
            resizable: false,
            onClose: function () {
                $(".maincontent").unmask()
            }
        });

        _f.window("open")
    })
    //}}}

})











